import java.util.HashSet;

public class test1062 {
    public int longestRepeatingSubstring(String s) {
    int len = s.length();
    int left = 1;
    int right = len;
        while(left <= right){
            int mid = left+(right-left)/2;
            if(search(mid,len,s) != -1) {left = mid+1;}
            else right = mid-1;
        }
        return left - 1;
    }
    public int search(int mid,int len,String s){
        HashSet<String> set = new HashSet();
        for(int i = 0;i < len - mid + 1;i ++){
            String str = s.substring(i,i+mid);
            if(set.contains(str.hashCode())) return i;
            set.add(str);
        }
        return -1;
    }
}
